/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uet.questiondetector.utils;

import edu.uet.questiondetector.factory.QuestionKeyword;
import java.util.ArrayList;
import java.util.List;
import vn.hus.nlp.tagger.VietnameseMaxentTagger;
import vn.hus.nlp.tokenizer.VietTokenizer;

/**
 *
 * @author thinhnk
 */
public class TaggerTool {
    private static TaggerTool tagger = null;
    VietTokenizer tokenizer;
    VietnameseMaxentTagger vntagger;
       
    private TaggerTool(){
        tokenizer = new VietTokenizer("data/");
        vntagger = new VietnameseMaxentTagger("data/", tokenizer);
    }
    
    public static TaggerTool instance(){
        if(tagger == null){
            tagger = new TaggerTool();
            return tagger;
        }else{
            return tagger;
        }
    }
    
    public String tag(String text){
        return vntagger.tagText(text);
    }
    
    public String[] tokenize(String text){
        return tokenizer.segment(text).split("\\s");
    }

    
    public List<WordToken> tagToList(String text){
        List<WordToken> wordList = new ArrayList<>();
        String[] words = vntagger.tagText(text).split("\\s");
        String [] temp = null;
        for(String w: words){
            temp = w.split("/");
            System.out.println(temp.length);
            System.out.println(temp[0]);
            wordList.add(new WordToken(temp[0], temp[1]));
        }
        return wordList;
    }
}
